clear all 
use "data\out\estsample.dta", clear
g byte PeakxEvent = Peak*EventDay
g byte ShoulderxEvent = shoulder*EventDay

* Redefine post as any day after the first event day and not itself an event day 
replace days_after = 1 if dato > 21893 & EventDay == 0 

drop TPnextdays TNPnextdays TPnextdayselcar TNPnextdayselcar
g byte TPnextdays = Treat*Peak*days_after
g byte TNPnextdays = Treat*NonPeak*days_after

drop Effektprisnext EffektprisNonPeaknext Effektprisnextelcar EffektprisNonPeaknextelcar
g byte Effektprisnext = (Treat == 1 & noncomplier == 0 & days_after == 1 & Peak == 1) | (Treat == 0 & noncomplier == 1 & days_after == 1 & Peak == 1)
g byte EffektprisNonPeaknext = (Treat == 1 & noncomplier == 0 & days_after == 1 & Peak == 0) | (Treat == 0 & noncomplier == 1 & days_after == 1 & Peak == 0)

foreach y in TPnextdays TNPnextdays Effektprisnext EffektprisNonPeaknext {
g byte `y'elcar = `y'*elcar 
}


ivreghdfe lnforbruk c.temp##c.temp##c.temp temp_* Peak PeakxEvent ShoulderxEvent Peakelcar shoulder shoulderelcar ///
  (Effektpris EffektprisNonPeak Effektprisnext EffektprisNonPeaknext Effektpriselcar EffektprisNonPeakelcar Effektprisnextelcar EffektprisNonPeaknextelcar Effektprisshoulder Effektprisshoulderelcar =  TPE TNPE TPnextdays TNPnextdays TPEelcar TNPEelcar TPnextdayselcar TNPnextdayselcar TsE TsEelcar), absorb(maalepktnr dato) cluster(maalepktnr)
est store IV5
estadd ysumm  


estout IV5 using "output\table_C6_persistence.txt", replace type ///
  cells(b( fmt(3)) se(par fmt(3)) _star) indicate(temp) mlabels(1 2 3 4 5 6 ) collabels(none) legend ///
  order(Effektpris EffektprisNonPeak Effektprisnext EffektprisNonPeaknext Peak PeakxEvent ShoulderxEvent Effektpriselcar EffektprisNonPeakelcar Effektprisnextelcar EffektprisNonPeaknextelcar Peakelcar Effektprisshoulder shoulder Effektprisshoulderelcar shoulderelcar) ///
  varlabels(TPE TP TNPE TNP) starlevels(* 0.10 ** 0.05 *** 0.01) varwidth(26) ///
  stats(ymean r2 N, fmt(3 3 0 0)) style(tex)
